<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <%@include file="/WEB-INF/views/include/weixinhead.jsp" %>
    <script src="${ctxStatic}/modules/wechat/js/rip.js"></script>
</head>
<body>
<!--创业资金管理-->
<div data-role="page" id="startup-fund-management" class="page" >
    <div data-role="header" class="header header-1" id="header">创业资金管理
        <span class="return-btn"><a href="/f/campusinfo/startupManagement" data-transition="slideup" data-ajax="false"><img src="${ctxStatic}/modules/wechat/css/images/yuanjiaojuxing25.png" alt=""></a></span>
    </div>
    <div role="main" class="content-1">
        <div id="enterprise-information">
            <div id="enterprise-name"></div>
            <div id="fund-management-account">资金管理账户</div>
            <div id="constitute" class="">
                <div class="totalFunds" style="background-color: #46ca98;"><!--background-color: #f3f3f3;-->
                    <div class="total-left">总监管资金（元）</div>
                    <div class="total-right" id="total-funds"></div>
                </div>
                <div class="totalFunds" style="background-color:  #46ca98;"><!--background-color: #ffffff;-->
                    <div class="total-left" style=" color:#ffffff;">监管资金构成（元）:</div>
                </div>
                <div class="table" id="consist">
                    <%--<div class="members">--%>
                    <%--<span class="members-name">张三</span>--%>
                    <%--<span class="members-funds">5000</span>--%>
                    <%--</div>--%>
                    <%--<div class="members">--%>
                    <%--<span class="members-name">张三</span>--%>
                    <%--<span class="members-funds">5000</span>--%>
                    <%--</div>--%>
                    <%--<div class="members">--%>
                    <%--<span class="members-name">张三</span>--%>
                    <%--<span class="members-funds">5000</span>--%>
                    <%--</div>--%>
                </div>
            </div>
            <div id="fund-management">
                 <span class="Amount-management">
                     <label>已提取金额(元)</label>
                     <label id="Applied-amount" ></label>
                </span>
                <span  class="Amount-management">
                    <label>当前余额(元)</label>
                    <label id="Current-balance"></label>
                </span>
                <span class="Amount-management">
                     <label>可用余额(元)</label>
                     <label id="Available-balance" ></label>
                </span>
            </div>
        </div>
        <div id="apply">
            <div class="completeLoadingOfResources" id="account" style="display: none">没有账户信息</div>
            <div class="completeLoadingOfResources" id="records" style="display: none">没有记录</div>
        </div>
    </div>
</div>
<%--资金申请--%>
<div id="ApplicationOfFunds"  data-role="page">
    <div data-role="header" class="header header-1">资金申请
        <span class="return-btn"><a href="#startup-fund-management" data-ajax="false" data-transition="slideup"><img src="${ctxStatic}/modules/wechat/css/images/yuanjiaojuxing25.png" alt=""></a></span>
    </div>
    <div role="main" class="content-2"  style="padding:12px;padding-top: 20px;">
        <div class="LostAndFound">申请公司
            <input id="companyName" type="text" readonly >
        </div>
        <div class="LostAndFound">申请金额(元)
            <input type="text" placeholder="请输入申请金额" class="non-empty nonnegative">
        </div>
        <div class="LostAndFound">申请用途
            <input type="text" placeholder="请输入申请用途" class="non-empty">
        </div>
        <button id="submitReplyBtn" disabled>提交</button>
    </div>
</div>
<script>
    $(document).ready(function() {
        var companyId ="";
        var apply=false;
        /*先判断用户是否在线*/
        $.ajax({
            url: interfaceGetState+generateMixed(9),
            type: 'post',
            success: function (data) {
                if (data.status == 0) {    //已登录
                    var companyName;
                    $.ajax({
                        url:interfaceApplyFundsYON+generateMixed(9),
                        type:'post',
                        success:function(data){
                            if(data.success){
                               $("#header").prepend("<span><a id=\"applyFunds\" href=\"#ApplicationOfFunds\" data-transition=\"slideup\" data-ajax=\"false\"><span>资金申请</span></a></span>");
                            }
                        }
                    })
                    $.ajax({
                        url: interfaceApplyFundsList+generateMixed(9), //查看资金
                        type: 'post',
                        success: function (data) {
                            // console.log(data);
                            /*添加监管资金构成*/
                            var searchlength = data.companySearchs.length;
                            var consistlength = data.campusinfoConsists.length;
                            var totalFunds=0;
                            if(consistlength!=0){
                                for (var i = 0; i < consistlength; i++) {
                                    $("#consist").append("<div class=members>" +
                                        "                <span class='members-name'>" + data.campusinfoConsists[i].fundName +"</span>" +
                                        "                <span class='members-funds'>" + data.campusinfoConsists[i].fund +
                                        "                </span>" +
                                        "            </div>");
                                    totalFunds+=parseFloat(data.campusinfoConsists[i].fund);
                                }
                                $("#total-funds").text(parseFloat(totalFunds).toFixed(2));
                            }
                            if(searchlength!=0){
                                $("#enterprise-name").text(data.companySearchs[0].companyName);   //公司名
                                $("#Current-balance").text(data.companySearchs[0].curRemainder);   //当前余额
                                $("#Available-balance").text(data.companySearchs[0].avaRemainder); //可用余额
                                $("#Applied-amount").text(data.companySearchs[0].reqRemainder);    //已提取金额
                                companyName = data.companySearchs[0].companyName;
                                companyId = data.companySearchs[0].companyId;
                                $("#companyName").val(data.companySearchs[0].companyName);
                                var length = data.page.length;
                                if(length!=0){
                                    $("#account").hide();
                                    $("#records").hide();
                                }
                                for (var i = 0; i < length; i++) {
                                    var applyBorder, applyImg, reply,status;
                                    // console.log(data.page[i].reqStatus);
                                    switch (data.page[i].reqStatus) {
                                        case '1':     //待审核
                                            applyBorder = "apply-check-aside";
                                            applyImg = "apply-check";
                                            status='待发放';
                                            break;
                                        case '2':     //审核中
                                            applyBorder = "apply-check-aside";
                                            applyImg = "apply-checking";
                                            status='待发放';
                                            break;
                                        case '3':      //完成
                                            applyBorder = "apply-pass-aside";
                                            applyImg = "apply-pass";
                                            status='已发放';
                                            break;
                                    }
                                    reply = data.page[i].reqReply;
                                    if (!reply) {
                                        reply = '';
                                    }else{
                                        // reply = '同意发放'+reply+"元";
                                    }
                                    /*添加申请记录*/
                                    $("#apply").append("<div class='apply enterprise " + applyImg + "'>" +
                                        "                <div class='apply-aside " + applyBorder + "' style='height:143px'></div>" +
                                        "                <div class='enterprise-content'>" +
                                        "                    <div class='enterprise-content-left'>申请金额(元)</div>" +
                                        "                    <div class='enterprise-content-right'>" + data.page[i].reqFunds + "</div>" +
                                        "                    <div class='enterprise-content-left'>申请用途</div>" +
                                        "                    <div class='enterprise-content-right'>" + data.page[i].reqPurpose + "</div>" +
                                        "                    <div class='enterprise-content-left'>审批意见</div>" +
                                        "                    <div class='enterprise-content-right'>" + reply + "</div>" +
                                        "                    <div class='enterprise-content-left'>资金发放状态</div>" +
                                        "                    <div class='enterprise-content-right'>" + status + "</div>" +
                                        "                </div>" +
                                        "                <div class='apply-time'>申请时间:<label style='display: inline'>" + data.page[i].updateDate + "</label></div>" +
                                        "            </div>");

                                }
                            }else{
                                $("#applyFunds").attr("href","#");
                                $("#account").show();
                                $("#records").hide();
                            }
                        }
                    })
                } else {    //未登录
                    if (window.sessionStorage) {
                        sessionStorage.setItem("prePage", "/f/campusinfo/startupFundManagement");
                    }
                    alert("请先登录");
                    window.location.href = "/f/campusinfo/login"+generateMixed(9);
                    return false;
                }
            }
        })
        /*提交报名*/
        $("#submitReplyBtn").off("tap").on("tap", function () {
            $("#submitReplyBtn").attr("disabled","disabled");
                /*先判断用户是否在线*/
                $.ajax({
                    url: interfaceGetState,
                    type: 'post',
                    success: function (data) {
                        if (data.status == 0) {    //已登录
                            var AmountOfMoney = $(".non-empty").eq(0).val();
                            var purpose = $(".non-empty").eq(1).val();
                            if (AmountOfMoney != '' && purpose != '') {
                                $.ajax({
                                    url: interfaceApplyFunds,
                                    type: 'post',
                                    data: {companyId: companyId, reqFunds: AmountOfMoney, reqPurpose: purpose},
                                    success: function (data) {
                                        // console.log(data);
                                        if (data.success) {
                                            alert(data.message);
                                            window.location = "/f/campusinfo/startupFundManagement"+generateMixed(9);
                                        } else {
                                            alert(data.message);
                                        }
                                    }
                                });
                            }else{
                                $("#submitReplyBtn").attr("disabled","disabled");
                            }
                        } else {    //未登录
                            alert("请先登录");
                            if (window.sessionStorage) {
                                sessionStorage.setItem("prePage", "/f/campusinfo/startupFundManagement#ApplicationOfFunds");
                            }
                            window.location.href = "/f/campusinfo/login"+generateMixed(9);
                        }
                    }
                })
            setTimeout(function(){
                $("#submitReplyBtn").removeAttr("disabled");
            },1000);
            });
        $("input").bind("input propertychange",function(){
            var AmountOfMoney = $(".non-empty").eq(0).val();
            var purpose = $(".non-empty").eq(1).val();
            if (AmountOfMoney != '' && purpose !='') {
                $("#submitReplyBtn").removeAttr("disabled");
            }else{
                $("#submitReplyBtn").attr("disabled","disabled");
            }
        })
    })
</script>
</body>
</html>